package com.kaifamiao.loginmodel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/check")
    public Map<String, Object>  getUserByName(@RequestParam("username") String username,
                                    @RequestParam("password") String password) {

        UserEntity user =userService.getUserByName(username);
        Map<String, Object> response = new HashMap<>();
        if (user.getPassword().equals(password)){

            response.put("code", "200");
            response.put("status", "success");
            response.put("message", "login successfully.");
        }else{
            response.put("code", "250");
            response.put("status", "error");
            response.put("message", "login error.");
        }

        return response;
    }

    @RequestMapping("/login")
    public ModelAndView login() {
        return new ModelAndView("login");
    }



}